﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Check;
using pay.Entity;
using pay.BLL;
using System.Text;

public partial class ePioneer_pay1 : System.Web.UI.Page
{
    protected int ProId = 0;
    protected string Mobile = "";
    protected string sMobile = "";
    protected int Num = 0;
    protected string Name = "";

    protected string ProInfo = "";

    protected string ErrMsg = "";
    //总金额
    protected float tPrice = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!int.TryParse(Request.Form["rdProId"], out ProId)) 
        {
            ProId = 0;
        }

        if (!int.TryParse(Request.Form["txtNum"], out Num))
        {
            Num = 0;
        }

        if (!string.IsNullOrEmpty(Request.Form["txtMobile"]))
        {
            Mobile = Request.Form["txtMobile"];
            sMobile = Mobile.Substring(0, 3) + "****" + Mobile.Substring(7);
        }

        if (!string.IsNullOrEmpty(Request.Form["txtName"]))
        {
            Name = Request.Form["txtName"];
        }

        if (ProId != 0 && Num != 0 && Mobile != "" && Name != "")
        {
            showProInfo();
            SaveOrderInfo();
        }
        else 
        {
            ErrMsg += "要购买的产品信息不正确，请重新选择。";
        }      

        if (ErrMsg != "") 
        {
            Response.Write("<script type=\"\">alert(\"" + ErrMsg + "\");window.location='pay.aspx'</script>");
            Response.End();
        }
    }

    protected void showProInfo()
    {
        StringBuilder sb = new StringBuilder();
        float price = 0;
        switch (ProId){
            case 20:
                sb.AppendFormat("<td align=\"center\">测试商品</td>\r\n");
                price = 0.01F;
                break;
            case 43:
                sb.AppendFormat("<td align=\"center\">益盟操盘手L2盯盘先锋年版</td>\r\n");
                price = 3380;
                break;
            case 48:
                sb.AppendFormat("<td align=\"center\">益盟操盘手L2盯盘先锋月版</td>\r\n");
                price = 299;
                break;
            default:
                return;
        }

        tPrice = price * Num;
        sb.AppendFormat("<td align=\"center\">{0}</td>\r\n", Num);
        sb.AppendFormat("<td align=\"center\">￥{0}</td>\r\n", tPrice);

        ProInfo = sb.ToString();
    }

    private void SaveOrderInfo()
    {
        Session["uname"] = Name;
        Session["tel"] = Mobile;
        Session["Linkman"] = Mobile;

        try
        {
            List<ShopCard> lst = new List<ShopCard>();
            ShopCard sc = new ShopCard();
            sc.Count = Num;
            sc.ProductId = ProId;
            sc.Price = tPrice;
            lst.Add(sc);
            Session["EmoneyShopCard"] = lst;
        }
        catch (Exception ex)
        {
            ErrMsg += "产品初始化异常，请重新选择。";
        }
    }    
}